<?php
class Sala extends AppModel {
	
	var $belongsTo = array('Piso');
	
	var $hasMany = array('Agenda','MedicoHorario');
	
	var $displayField = 'nome';
	
	var $validate = array(
        'nome' => array(
            'vazio' => array(
                'rule' => 'notEmpty',
                'required' => true,
                'message' => 'Nome deve ser informado!',
                'last' => true
			)
		),
        'piso_id' => array(
            'vazio' => array(
                'rule' => 'notEmpty',
                'required' => true,
                'message' => 'Piso deve ser informado!',
                'last' => true
			)
		)		
	);	
	
	public function get_list_sala_piso() {
		
		$result = $this->find('all', array('recursive' => 0, 'fields' => array('id', 'Sala.nome','Piso.nome'), 'order' => array('Piso.nome')));
		
		$ret = array();
		
		foreach($result as $rs) {
			$ret[$rs['Sala']['id']] = $rs['Piso']['nome'] . ' - ' . $rs['Sala']['nome'];
		}
		
		return $ret;
	}
	
}
